Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Extensible string utility for converting, identifying and flipping string case
The 'case' npm package provides utilities for converting strings between different case styles, such as camelCase, snake_case, and more. It is useful for formatting strings in a consistent manner across different parts of an application.
camel
Converts a string to camelCase. This is useful for JavaScript variable naming conventions.
const case = require('case');
console.log(case.camel('hello world')); // 'helloWorld'
snake
Converts a string to snake_case. This is often used in Python variable naming conventions or for database column names.
const case = require('case');
console.log(case.snake('hello world')); // 'hello_world'
kebab
Converts a string to kebab-case. This is commonly used in URLs or CSS class names.
const case = require('case');
console.log(case.kebab('hello world')); // 'hello-world'
title
Converts a string to Title Case. This is useful for formatting titles or headings.
const case = require('case');
console.log(case.title('hello world')); // 'Hello World'
constant
Converts a string to CONSTANT_CASE. This is often used for constants in programming.
const case = require('case');
console.log(case.constant('hello world')); // 'HELLO_WORLD'
The 'change-case' package provides similar functionality for converting strings between different case styles. It offers a more modular approach, allowing you to import only the specific case functions you need, which can help reduce bundle size.
Lodash is a utility library that includes functions for case conversion among many other utilities. While it is more comprehensive and widely used, it may be overkill if you only need case conversion functionalities.
The 'camelcase' package focuses specifically on converting strings to camelCase. It is lightweight and does one thing well, making it a good choice if camelCase conversion is all you need.
Download: Case.min.js or Case.js
NPM: npm install case
(little 'c' due to NPM restrictions)
NuGet: Install-Package Case
Each of the following functions will first "undo" previous case manipulations before applying the desired case to the given string.
Case.upper('foo_bar') -> 'FOO BAR'
Case.lower('fooBar') -> 'foo bar'
Case.capital('foo_v_bar') -> 'Foo V Bar'
Case.snake('Foo bar!') -> 'foo_bar'
Case.pascal('foo.bar') -> 'FooBar'
Case.camel('foo, bar') -> 'fooBar'
Case.kebab('Foo? Bar.') -> 'foo-bar'
Case.header('fooBar=') -> 'Foo-Bar'
Case.constant('Foo-Bar') -> 'FOO_BAR'
Case.title('foo v. bar') -> 'Foo v. Bar'
Case.sentence('"foo!" said bar', ['Bar']) -> '"Foo!" said Bar'
Case.sentence('the 12 oz. can', null, ['oz']) -> 'The 12 oz. can'
Case.sentence(str, names, abbreviations)
accepts an array of proper names that should be capitalized,
regardless of location in the sentence. This function is specialized, but useful
when dealing with input generated with capslock on (i.e. everything my grandma types).
It can also accept a list of abbreviations (words that may end in a period but aren't meant
to end a sentence).
Case.lower('FOO-BAR', '.') -> 'foo.bar'
Case.upper('Foo? Bar.', '__') -> 'FOO__BAR'
Case.capital('fooBar', ' + ') -> 'Foo + Bar'
Case.lower("Don't keep 'em!", "/", true) -> 'dont/keep/em'
Case.capital("'ello, world.", null, true) -> 'Ello, World.'
Case.upper
, Case.lower
, and Case.capital
accept an optional "fill" value
that will replace any characters which are not letters and numbers. All three also accept
a third optional boolean argument indicating if apostrophes are to be stripped out or left in.
For example, programmatic case changes (snake, kebab, pascal, camel, constant) are best without
apostrophes, but user-facing ones (title, sentence) do not want "don't" turned into "Dont".
Case.type('bang', function(s) {
return Case.upper(s, '!')+'!';
});
Case.bang('bang') -> 'BANG!'
Case.of('TEST!THIS!') -> 'bang'
Case.type(name, fn)
: extends Case, creating a new function on Case
and adding Case.of
support automatically.
Case.of('foo') -> 'lower'
Case.of('foo_bar') -> 'snake'
Case.of('Foo v Bar') -> 'title'
Case.of('foo_ Bar') -> undefined
Case.of('Hello there, Bob!', ['Bob']) -> 'sentence'
Case.flip('FlipMe') -> 'fLIPmE'
Case.flip('TEST THIS!') -> 'test this!'
Case.random('Hello!') -> 'hElLO!'
Case.of(str[, names])
: identifies the case of a string, returns undefined if it doesn't match a known typeCase.flip(str)
: reverses the case of letters, no other changesCase.random(str)
: randomizes the case of letters, no other changesFAQs
Extensible string utility for converting, identifying and flipping string case
The npm package case receives a total of 732,222 weekly downloads. As such, case popularity was classified as popular.
We found that case demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.